// my/pages/Sign/Sign.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 当前选中的学科
    currentSubject: 'physics',
    
    // 学科信息
    subjectInfo: {
      physics: {
        name: '物理',
        desc: '探索自然规律，理解宇宙奥秘',
        streak: 7,
        score: 850,
        rank: 45,
        signReward: 50
      },
      chemistry: {
        name: '化学',
        desc: '研究物质组成，探索化学反应',
        streak: 5,
        score: 620,
        rank: 32,
        signReward: 45
      },
      biology: {
        name: '生物',
        desc: '了解生命现象，探索生物奥秘',
        streak: 10,
        score: 980,
        rank: 28,
        signReward: 55
      },
      politics: {
        name: '政治',
        desc: '理解社会制度，把握时代脉搏',
        streak: 3,
        score: 420,
        rank: 67,
        signReward: 40
      }
    },
    
    // 签到状态
    hasSigned: false,
    signRate: 78,
    
    // 日历数据
    calendarDays: [
      { day: '1', date: '2023-10-01', status: 'signed', hasSign: true, subject: 'physics' },
      { day: '2', date: '2023-10-02', status: 'signed', hasSign: true, subject: 'chemistry' },
      { day: '3', date: '2023-10-03', status: 'signed', hasSign: true, subject: 'biology' },
      { day: '4', date: '2023-10-04', status: 'signed', hasSign: true, subject: 'physics' },
      { day: '5', date: '2023-10-05', status: 'signed', hasSign: true, subject: 'politics' },
      { day: '6', date: '2023-10-06', status: 'signed', hasSign: true, subject: 'chemistry' },
      { day: '7', date: '2023-10-07', status: 'current', hasSign: true, subject: 'biology' },
      { day: '8', date: '2023-10-08', status: '', hasSign: false },
      { day: '9', date: '2023-10-09', status: '', hasSign: false },
      { day: '10', date: '2023-10-10', status: '', hasSign: false },
      { day: '11', date: '2023-10-11', status: '', hasSign: false },
      { day: '12', date: '2023-10-12', status: '', hasSign: false },
      { day: '13', date: '2023-10-13', status: '', hasSign: false },
      { day: '14', date: '2023-10-14', status: '', hasSign: false }
    ],
    
    // 签到奖励
    signRewards: [
      {
        id: 1,
        name: '连续签到3天',
        desc: '获得额外积分奖励',
        icon: '/images/reward1.png',
        status: 'completed',
        statusText: '已完成'
      },
      {
        id: 2,
        name: '连续签到7天',
        desc: '获得学科徽章',
        icon: '/images/reward2.png',
        status: 'completed',
        statusText: '已完成'
      },
      {
        id: 3,
        name: '连续签到30天',
        desc: '获得VIP体验',
        icon: '/images/reward3.png',
        status: 'pending',
        statusText: '进行中'
      },
      {
        id: 4,
        name: '全学科签到',
        desc: '获得全科学霸称号',
        icon: '/images/reward4.png',
        status: 'locked',
        statusText: '未解锁'
      }
    ],
    
    // 学科成就
    subjectAchievements: [
      {
        id: 1,
        name: '物理新星',
        icon: '/images/physics-achievement.png',
        progress: '7/10'
      },
      {
        id: 2,
        name: '化学达人',
        icon: '/images/chemistry-achievement.png',
        progress: '5/10'
      },
      {
        id: 3,
        name: '生物专家',
        icon: '/images/biology-achievement.png',
        progress: '10/10'
      },
      {
        id: 4,
        name: '政治学者',
        icon: '/images/politics-achievement.png',
        progress: '3/10'
      },
      {
        id: 5,
        name: '全科学霸',
        icon: '/images/all-subject-achievement.png',
        progress: '25/40'
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.loadSubjectData();
    this.loadCalendarData();
    this.loadRewards();
    this.loadAchievements();
  },
  
  /**
   * 加载学科数据
   */
  loadSubjectData() {
    // 这里可以添加从服务器获取学科数据的逻辑
    console.log('加载学科数据');
  },
  
  /**
   * 加载日历数据
   */
  loadCalendarData() {
    // 这里可以添加从服务器获取日历数据的逻辑
    console.log('加载日历数据');
  },
  
  /**
   * 加载奖励数据
   */
  loadRewards() {
    // 这里可以添加从服务器获取奖励数据的逻辑
    console.log('加载奖励数据');
  },
  
  /**
   * 加载成就数据
   */
  loadAchievements() {
    // 这里可以添加从服务器获取成就数据的逻辑
    console.log('加载成就数据');
  },
  
  /**
   * 切换学科
   */
  switchSubject(e) {
    const subject = e.currentTarget.dataset.subject;
    this.setData({
      currentSubject: subject
    });
    
    // 重新加载该学科的数据
    this.loadSubjectData();
  },
  
  /**
   * 执行签到
   */
  doSign() {
    const currentSubject = this.data.currentSubject;
    const subjectData = this.data.subjectInfo[currentSubject];
    
    // 模拟签到成功
    this.setData({
      hasSigned: true
    });
    
    // 更新学科数据
    const newSubjectInfo = { ...this.data.subjectInfo };
    newSubjectInfo[currentSubject].streak += 1;
    newSubjectInfo[currentSubject].score += subjectData.signReward;
    
    this.setData({
      subjectInfo: newSubjectInfo
    });
    
    wx.showToast({
      title: `签到成功！获得${subjectData.signReward}积分`,
      icon: 'success'
    });
  },
  
  /**
   * 查看日期详情
   */
  viewDayDetail(e) {
    const date = e.currentTarget.dataset.date;
    wx.showToast({
      title: `查看${date}的签到详情`,
      icon: 'none'
    });
  },
  
  /**
   * 查看全部奖励
   */
  viewAllRewards() {
    wx.showToast({
      title: '查看全部奖励功能开发中',
      icon: 'none'
    });
  },
  
  /**
   * 查看全部成就
   */
  viewAllAchievements() {
    wx.showToast({
      title: '查看全部成就功能开发中',
      icon: 'none'
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})